package com.acme;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PlayerListAdapter extends ArrayAdapter<Player> {
	
	public PlayerListAdapter(Context context, int textViewResourceId, Player[] players) {
		super(context, textViewResourceId, players);
		Log.i("PlayerListAdapter", "Constructor");
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
		
            View v = convertView;
            
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                //v = vi.inflate(R.layout.player_list_item, null);
                v = vi.inflate(R.layout.player_list_item, parent, false);
            }
            
            Player p = getItem(position);
            if (p != null) {
            	
				Log.i("PlayerListAdapter", "player: "+p);
				
                TextView name = (TextView) v.findViewById(R.id.name);
                TextView player_position = (TextView) v.findViewById(R.id.position);
                TextView team = (TextView) v.findViewById(R.id.team);
                
                name.setText(p.firstName+" "+p.lastName);
               	player_position.setText(p.positions[0]);
               	team.setText(p.teams[0]);
            }
            return v;
    }
	
}
